//JavaScript Framework 2.0 Code
try{
Type.registerNamespace('com.yonyou.ncmm_pac_pda.TransInQueryController');
com.yonyou.ncmm_pac_pda.TransInQueryController = function() {
    com.yonyou.ncmm_pac_pda.TransInQueryController.initializeBase(this);
    this.initialize();
}
function com$yonyou$ncmm_pac_pda$TransInQueryController$initialize(){
    //you can programing by $ctx API
    //get the context data through $ctx.get()
    //set the context data through $ctx.push(json)
    //set the field of the context through $ctx.put(fieldName, fieldValue)
    //get the parameter of the context through $ctx.param(parameterName)
    //Demo Code:
    //    var str = $ctx.getString();      //获取当前Context对应的字符串
    //    alert($ctx.getString())          //alert当前Context对应的字符串
    //    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
    //    json["x"] = "a";        //为当前json增加字段
    //    json["y"] = [];           //为当前json增加数组
    //    $ctx.push(json);            //设置context，并自动调用数据绑定
    //    
    //    put方法需手动调用databind()
    //    var x = $ctx.get("x");    //获取x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
    //    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
    //    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
    //    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组
    
    //your initialize code below...
    
}
    
function com$yonyou$ncmm_pac_pda$TransInQueryController$evaljs(js){
    eval(js)
}
function com$yonyou$ncmm_pac_pda$TransInQueryController$cancle(sender, args){
    $view.close();
}
function com$yonyou$ncmm_pac_pda$TransInQueryController$doClear(sender, args){
    var json={};
    $ctx.push(json);
}
//物料参照
function com$yonyou$ncmm_pac_pda$TransInQueryController$materialRef(sender, args){
    openRefPage("PDAMATERIAL", "qmaterial","cmaterialvid","pk_material");
}
//部门参照
function com$yonyou$ncmm_pac_pda$TransInQueryController$deptRef(sender, args){
    openRefPage("PDADEPT", "qdept","cdeptid","pk_dept");
}
//库存组织参照
function com$yonyou$ncmm_pac_pda$TransInQueryController$orgRef(sender, args){
    openRefPage("PDASTOCKORG", "qorg","corgid","pk_stockorg");
}
//调出组织参照
function com$yonyou$ncmm_pac_pda$TransInQueryController$outorgRef(sender, args){
    openRefPage("PDASTOCKORG", "qoutorg","coutorgid","pk_stockorg");
}
//仓库参照
function com$yonyou$ncmm_pac_pda$TransInQueryController$stockRef(sender, args){
    openRefPage("PDASTORDOC", "qstock","cstockid","pk_stockorg");
}
//打开参照界面
function openRefPage(ncbillcode, ctxnamekey,ctxpkkey,pkfiel) {
    var jsonparam = {};
    getRefParam(ncbillcode, function(data) {
        jsonparam = data;
    });
    if(jsonparam == null) {
        return;
    }
    $view.open({
        viewid: "com.yonyou.ncmm_pac_pda.RefPage",
        isKeep: "true",
        data: jsonparam,
        callback: function() {
            var refdata = $param.getJSONObject("data");
            $ctx.put(ctxnamekey, refdata["name"]);
            $ctx.put(ctxpkkey, refdata[pkfiel]);
            $ctx.dataBind();
            $cache.write("default" + ctxnamekey, $jsonToString(refdata));
        }
    });
}
//获取参照vo的vo信息
function getRefParam(reftype, callback) {
    var condition = {
        "ncbillcode": reftype
    }
    NCMMPubUtil.queryVOByConditions(AppmappingheadVO, condition, function(data) {
        var jsondata = {
            bdlistdata: eval(data)
        };
        var reftitle = (jsondata.bdlistdata)[0]["appbillname"];
        if((jsondata.bdlistdata)[0]["downloadnum"] == "" || (jsondata.bdlistdata)[0]["downloadnum"] == "0") {
            $alert("【" + reftitle + "】没有可参照的数据");
            if(callback != null && callback != undefined && typeof(callback) == 'function') {
                callback(null);
            }
            return;
        }
        var reftablename = (jsondata.bdlistdata)[0]["apptablename"];
        var jsonparam = {
            reftype: reftype,
            reftitle: reftitle,
            reftablename: reftablename
        }
        if(callback != null && callback != undefined && typeof(callback) == 'function') {
            callback(jsonparam);
        }
    });
}
//执行查询
function com$yonyou$ncmm_pac_pda$TransInQueryController$doQuery(sender, args){
    var condition = {};
    $ctx.dataCollect();
    //物料 
    if($id("qmaterial").get("value") != "") {
        condition["cmaterialvid"] = " = '" + $ctx.getString("cmaterialvid") + "'";
    }
    //单据号
    if($id("qbillcode").get("value") != "") {
        condition["vbillcode"] = " = '" + $id("qbillcode").get("value").toString() + "'";
    }
    //部门
    if($id("qdept").get("value") != "") {
        condition["cdptvid"] = " = '" + $ctx.getString("cdeptid") + "'";
    }
    //库存组织
    if($id("qorg").get("value") != "") {
        condition["pk_org"] = " = '" + $ctx.getString("corgid") + "'";
    }
    //仓库
    if($id("qstock").get("value") != "") {
        condition["cwarehouseid"] = " = '" + $ctx.getString("cstockid") + "'";
    }
    //调出组织
    if($id("qoutorg").get("value") != "") {
		condition["coutcalbodyoid"] = " = '" + $ctx.getString("coutorgid") + "'";
	}
	//批次号
	if($id("qbatchcode").get("value") != "") {
	    condition["vbatchcode"] = " = '" + $id("qbatchcode").get("value").toString() + "'";
	}
	//日期
	if($id("qbilldatestar").get("value") != "" && $id("qbilldateend").get("value") != "") {
	    condition["dbilldate"] = "between '" + $id("qbilldatestar").get("value").toString() + " 00:00:00" + "' and '" + $id("qbilldateend").get("value").toString() + " 23:59:59" + "'";
	} else {
	    //单据日期从
	    if($id("qbilldatestar").get("value") != "") {
	        condition["dbilldate"] = " >= '" + $id("qbilldatestar").get("value").toString() + " 00:00:00'";
	    }
	    //单据日期到
	    if($id("qbilldateend").get("value") != "") {
	        condition["dbilldate"] = " <= '" + $id("qbilldateend").get("value").toString() + " 23:59:59'";
	    }
	}
	$view.closeWithCallBack({
	    "qcondition": condition
	});
}
function com$yonyou$ncmm_pac_pda$TransInQueryController$onload(sender, args){
        var json = {};
		var nowdate = NCMMPubUtil.getNowDate();
		json["qbilldatestar"] = nowdate;
		json["qbilldateend"] = nowdate;
		//	$alert("json="+$jsonToString(json));
		$ctx.push(json);
}
com.yonyou.ncmm_pac_pda.TransInQueryController.prototype = {
    onload : com$yonyou$ncmm_pac_pda$TransInQueryController$onload,
    doQuery : com$yonyou$ncmm_pac_pda$TransInQueryController$doQuery,
    stockRef : com$yonyou$ncmm_pac_pda$TransInQueryController$stockRef,
    orgRef : com$yonyou$ncmm_pac_pda$TransInQueryController$orgRef,
    outorgRef : com$yonyou$ncmm_pac_pda$TransInQueryController$outorgRef,
    deptRef : com$yonyou$ncmm_pac_pda$TransInQueryController$deptRef,
    materialRef : com$yonyou$ncmm_pac_pda$TransInQueryController$materialRef,
    doClear : com$yonyou$ncmm_pac_pda$TransInQueryController$doClear,
    cancle : com$yonyou$ncmm_pac_pda$TransInQueryController$cancle,
    initialize : com$yonyou$ncmm_pac_pda$TransInQueryController$initialize,
    evaljs : com$yonyou$ncmm_pac_pda$TransInQueryController$evaljs
};
com.yonyou.ncmm_pac_pda.TransInQueryController.registerClass('com.yonyou.ncmm_pac_pda.TransInQueryController',UMP.UI.Mvc.Controller);
}catch(e){$e(e);}
